const latLonToMeters = (lat, lon, latOrigin, lonOrigin) => {
    const radius = 6378137; // 地球半径，单位米
    const lat1 = latOrigin * Math.PI / 180;
    const lat2 = lat * Math.PI / 180;
    const lon1 = lonOrigin * Math.PI / 180;
    const lon2 = lon * Math.PI / 180;
 
    const x = (lon2 - lon1) * radius * Math.cos((lat1 + lat2) / 2);
    const y = (lat2 - lat1) * radius;
 
    return [x, y];
}
 
const metersToLatLon = (x, y, latOrigin, lonOrigin) => {
    const radius = 6378137; // 地球半径，单位米
    const latOriginRad = latOrigin * Math.PI / 180;
    const lonOriginRad = lonOrigin * Math.PI / 180;
 
    const lat = (y / radius) + latOriginRad;
    const lon = lonOriginRad + (x / (radius * Math.cos(latOriginRad)));
 
    return [lat * 180 / Math.PI, lon * 180 / Math.PI];
}

export default {
   latLonToMeters,
   metersToLatLon
}